#!/usr/bin/env bash

set -o nounset
set -o errexit
set -o pipefail
set -o noclobber
set -o noglob

STARTUP_DIR="$( cd "$( dirname "$0" )" && pwd )"

source ${STARTUP_DIR}/../settings.sh

delete_job() {
    local job_name=$1
    echo "*** deleting job[${job_name}] ***"

    CRUMB=$(curl -s -u ${JENKINS_USER_NAME}:${JENKINS_USER_PASSWORD} 'http://localhost:9090/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)') && \
        curl -X POST -H $CRUMB "http:///${JENKINS_USER_NAME}:${JENKINS_USER_PASSWORD}@localhost:9090/job/${job_name}/doDelete" --header "Content-Type: application/xml" -d "dummy"

    echo "deleted ${job_name}"
}

main() {
    delete_job "get-all-job"
    delete_job "build-model-images-job"
}

main "@$"

